﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VLUSM_DataAccess.Repositories
{
    public class MonHocRepository : GenericRepository<DiemContainer>
    {
        public MonHocRepository(string connectionString) : base(connectionString, "Diem") { }
        public MonHocRepository(DiemContainer context) : base(context) { }

        public MonHoc GetSingleByID(int IDFilter)
        {
            var query = this.GetFirst<MonHoc>(d => d.ID == IDFilter);
            return query;
        }

        public MonHoc GetSingleByMaMonHoc(string MaMonHocFilter)
        {
            var query = this.GetFirst<MonHoc>(d => d.MaMonHoc == MaMonHocFilter);
            return query;
        }

        public MonHoc GetSingleByTen(string TenFilter)
        {
            var query = this.GetFirst<MonHoc>(d => d.TenGoi == TenFilter);
            return query;
        }

        public IEnumerable<MonHoc> GetAll()
        {
            var query = this.GetAll<MonHoc>();
            return query;
        }

        public IEnumerable<MonHoc> GetAllByNhomNguoiDung(string NhomNguoiDungFilter)
        {
            var query = this.GetAll<MonHoc>().Where(m => m.NhomNguoiDung == NhomNguoiDungFilter);
            return query;
        }

        public void Save(MonHoc obj)
        {
            try
            {
                if (obj.ID != 0)
                {
                    this.Attach<MonHoc>(obj);
                }
                else
                {
                    this.Add<MonHoc>(obj);
                }
            }
            catch { }
        }

        public void Remove(MonHoc obj)
        {
            this.Delete<MonHoc>(obj);
        }

        public void Remove(int IDFilter)
        {
            var obj = this.GetSingleOrDefault<MonHoc>(m => m.ID == IDFilter);
            this.Delete<MonHoc>(obj);
        }
    }
}
